package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.HouseNotice;
import com.stylefeng.guns.modular.system.service.IHouseNoticeService;

/**
 * 公告管理控制器
 *
 * @author leequn
 * @Date 2018-08-02 23:39:53
 */
@Controller
@RequestMapping("/houseNotice")
public class HouseNoticeController extends BaseController {

    private String PREFIX = "/system/houseNotice/";

    @Autowired
    private IHouseNoticeService houseNoticeService;

    /**
     * 跳转到公告管理首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "houseNotice.html";
    }

    /**
     * 跳转到添加公告管理
     */
    @RequestMapping("/houseNotice_add")
    public String houseNoticeAdd() {
        return PREFIX + "houseNotice_add.html";
    }

    /**
     * 跳转到修改公告管理
     */
    @RequestMapping("/houseNotice_update/{houseNoticeId}")
    public String houseNoticeUpdate(@PathVariable Integer houseNoticeId, Model model) {
        HouseNotice houseNotice = houseNoticeService.selectById(houseNoticeId);
        model.addAttribute("item",houseNotice);
        LogObjectHolder.me().set(houseNotice);
        return PREFIX + "houseNotice_edit.html";
    }

    /**
     * 获取公告管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return houseNoticeService.selectList(null);
    }

    /**
     * 新增公告管理
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(HouseNotice houseNotice) {
        houseNoticeService.insert(houseNotice);
        return SUCCESS_TIP;
    }

    /**
     * 删除公告管理
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer houseNoticeId) {
        houseNoticeService.deleteById(houseNoticeId);
        return SUCCESS_TIP;
    }

    /**
     * 修改公告管理
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(HouseNotice houseNotice) {
        houseNoticeService.updateById(houseNotice);
        return SUCCESS_TIP;
    }

    /**
     * 公告管理详情
     */
    @RequestMapping(value = "/detail/{houseNoticeId}")
    @ResponseBody
    public Object detail(@PathVariable("houseNoticeId") Integer houseNoticeId) {
        return houseNoticeService.selectById(houseNoticeId);
    }
}
